// 使用 multer 处理文件上传
const multer = require("multer");
const { v4: uuid } = require("uuid");
const path = require("path");

// 配置上传文件的存储位置和文件名
const genStorage = (pathname) => {
  return multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, pathname);
    },
    filename: function (req, file, cb) {
      const ext = path.extname(file.originalname);
      cb(null, uuid() + ext);
    },
  });
};

const avatar = multer({ storage: genStorage("./public/avatars") });
const pictures = multer({ storage: genStorage("./public/pictures") });

module.exports = { avatar, pictures };
